/**
 * 通用JS
 */
/** 格式化数字为千分符 */
function numberQ(num) {
    if (num && num !== "") {
        num = parseFloat(num);
        return (num.toFixed(2) + '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
    } else {
        return "0.00";
    }
}

function trim(str) {
    return str.replace(/\s+/g, "")
}

/** 格式化数字为千分符 */
function numberQFormatter(value) {
    return numberQ(value);
}

function numberQFormat(value) {
    return numberQ(value);
}

// 对Date的扩展，将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子：
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1,                 //月份
        "d+": this.getDate(),                    //日
        "h+": this.getHours(),                   //小时
        "m+": this.getMinutes(),                 //分
        "s+": this.getSeconds(),                 //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds()             //毫秒
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (const k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

function dateFormat(value, rowData, rowIndex) {
    if (value && value != "") {
        const s = value.split(" ");
        const s1 = s[0].split("-");
        return new Date(s1[0], s1[1] - 1, s1[2]).Format("yyyy-MM-dd");
    } else {
        return value;
    }

}

function dateTimeFormat(value) {
    if (value && value !== "") {
        const s = value.split(" ");
        const s1 = s[0].split("-");
        const s2 = s[1].split(":");
        if (s2.length === 2) {
            s2.push("00");
        }
        return new Date(s1[0], s1[1] - 1, s1[2], s2[0], s2[1], s2[2]).Format("yyyy-MM-dd hh:mm:ss");
    } else {
        return value;
    }
}

var __status = {"-3": "不通过", "-2": "删除", "-1": "禁用", "0": "待审核", "1": "正常", "2": "隐藏"}
var __sex = {"1": "男", "2": "女", "0": "未知"}

function statusStr(enumObj) {
    return __status[enumObj] || '';
}

function sexStr(enumObj) {
    return __sex[enumObj] || '';
}

/**
 * 获取当前模块URL
 *
 * @returns
 */
const tabUrl = function () {
    let frame = self.frameElement;
    if (frame) {
        let src = frame.src;
        let a = src.substring(src.indexOf(__basePath) + __basePath.length);
        a = a.substring(0, a.lastIndexOf("/"));
        return a;
    } else
        return "";
}
const tabName = function () {
    let frame = self.frameElement;
    if (frame) {
        let name = frame.name;
        return name;
    } else
        return "";
}

function post(url, params, success, fail) {
    console.log(params);
    // 打开一个加载层
    var loadIndex = layer.msg('提交中', {
        time: 0, // 90s 后自动关闭
        icon: 16, shade: 0.5
    });

    $.post(url, params, function (response) {
        layer.close(loadIndex)
        if (response.code > 0) {
            console.log(">0")
            if (success) {
                success(response)
            } else {
                layer.msg(response.msg, {icon: 1});
            }
        } else {
            console.log("<=0")
            if (fail) {
                fail()
            } else {
                layer.msg(response.msg, {icon: 5});
            }
        }
    }, 'json').fail(function () {
        layer.close(loadIndex)
        if (fail) {
            fail()
        } else {
            layer.msg("请求失败，请稍后再试", {icon: 5});
        }
    });
}

function successMsg(msg) {
    layer.msg(msg, {icon: 1});
}

function errorMsg(msg) {
    layer.msg(msg, {icon: 5});
}
function toast(msg) {
    layer.msg(msg);
}
function jsonString(obj) {
    return JSON.stringify(obj);
}

// if (!window.console || !console.firebug) {
//     const names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
//     window.console = {};
//     for (let i = 0; i < names.length; ++i) {
//         window.console[names[i]] = function () {
//         }
//     }
// }
// $(function () {
//     $(document).bind("contextmenu", function (e) {
//         return false;
//     });
// });
